package org.come.Jpanel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.util.List;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import org.come.bean.TeamBean;
import org.come.entity.TeamRole;
import org.come.mouslisten.TeamCreateModelListener;
import org.come.until.CutButtonImage;

import com.tool.btn.TeamCreateBtn;
import com.tool.tcpimg.UIUtils;

/**
 * 组队面板队伍信息模块面板
 * 
 * @author HGC<br>
 * @time 2019年12月30日 下午2:11:44<br>
 * @class 类名:TeamCreateModelJpanel<br>
 */
public class TeamCreateModelJpanel extends JPanel {

    /**
     * 字段名:labNum 编号<br>
     * 字段名:labRestrain 强克类型<br>
     * 字段名:labTeam 任务类型<br>
     * 字段名:labMsg 队伍简讯<br>
     * 
     * @time 2019年12月30日 下午2:12:33<br>
     */
    private JLabel labNum, labRestrain, labTeam, labMsg;
    /**
     * 字段名:labArrTeamImgs 组队成员人物头像 5个包含队长<br>
     * 
     * @time 2019年12月30日 下午2:14:33<br>
     */
    private JLabel[] labArrTeamImgs;
    private TeamCreateModelListener[] listenerTeamImgs;

    /**
     * 字段名:btnJoin 加入<br>
     * 字段名:btnChat 交谈<br>
     * 
     * @time 2019年12月30日 下午2:15:34<br>
     */
    private TeamCreateBtn btnJoin, btnChat;

    private TeamBean teamBean;

    public TeamCreateModelJpanel() {
        this.setPreferredSize(new Dimension(456, 50));
        this.setOpaque(false);
        this.setLayout(null);

        getLabArrTeamImgs();
        getLabNum();
        getLabRestrain();
        getLabTeam();
        getLabMsg();
        getBtnChat();
        getBtnJoin();
    }

    /**
     * 展示队伍数据
     * 
     * @time 2019年12月30日 下午4:51:35<br>
     * @param teamBean
     */
    public void showTeamBean(TeamBean teamBean) {
        this.teamBean = teamBean;
        if (teamBean != null) {
            labMsg.setText(teamBean.geteMsg());
            labRestrain.setText(teamBean.geteTeam());
            labNum.setText(null);
            labTeam.setText(teamBean.geteTask());
            List<TeamRole> teams = teamBean.getTeams();
            for (int i = 0; i < labArrTeamImgs.length; i++) {
                if (i < teams.size()) {
                    TeamRole teamRole = teams.get(i);
                    labArrTeamImgs[i].setIcon(CutButtonImage.getImage("img/head/s" + teamRole.getSpeciesId() + ".png",-1, -1));
                    listenerTeamImgs[i].setTeamRole(teamRole);
                } else {
                    labArrTeamImgs[i].setIcon(null);
                    listenerTeamImgs[i].setTeamRole(null);
                }
            }
        }
    }

    private ImageIcon icon;

    @Override
    protected void paintComponent(Graphics g) {
        // TODO Auto-generated method stub
        super.paintComponent(g);
        if (icon == null) {
            icon = CutButtonImage.getImage("inkImg/old/background/S162.png", -1, -1);
        }
        g.drawImage(icon.getImage(), 14, 49, 428, 1, null);
    }

    public JLabel getLabNum() {
        if (labNum == null) {
            labNum = new JLabel("171", SwingConstants.CENTER);
            labNum.setBounds(3, 13, 20, 16);
            labNum.setFont(UIUtils.TEXT_FONT);
            labNum.setForeground(Color.white);
            this.add(labNum);
        }
        return labNum;
    }

    public void setLabNum(JLabel labNum) {
        this.labNum = labNum;
    }

    public JLabel getLabRestrain() {
        if (labRestrain == null) {
            labRestrain = new JLabel("无属性");
            labRestrain.setBounds(243, 10, 60, 16);
            labRestrain.setForeground(Color.white);
            labRestrain.setFont(UIUtils.TEXT_FONT1);
            this.add(labRestrain);
        }
        return labRestrain;
    }

    public void setLabRestrain(JLabel labRestrain) {
        this.labRestrain = labRestrain;
    }

    public JLabel getLabTeam() {
        if (labTeam == null) {
            labTeam = new JLabel("其他");
            labTeam.setBounds(330, 10, 60, 16);
            labTeam.setForeground(Color.white);
            labTeam.setFont(UIUtils.TEXT_FONT1);
            this.add(labTeam);
        }
        return labTeam;
    }

    public void setLabTeam(JLabel labTeam) {
        this.labTeam = labTeam;
    }

    public JLabel[] getLabArrTeamImgs() {
        if (labArrTeamImgs == null) {
            labArrTeamImgs = new JLabel[5];
            listenerTeamImgs = new TeamCreateModelListener[5];
            for (int i = 0; i < labArrTeamImgs.length; i++) {
                labArrTeamImgs[i] = new JLabel() {

                    private ImageIcon icon;

                    @Override
                    protected void paintComponent(Graphics g) {
                        // TODO Auto-generated method stub
                        if (getIcon() == null) {
                            if (icon == null) {
                                icon = CutButtonImage.getImage("inkImg/old/2/S158.png", -1, -1);
                            }
                            g.drawImage(icon.getImage(), 0, 0, 39, 39, null);
                        }
                        super.paintComponent(g);
                    }
                };
                if (i == 0) {
                    labArrTeamImgs[i].setBounds(25, 0, 39, 39);
                } else {
                    labArrTeamImgs[i].setBounds(35 + i * 40, 0, 39, 39);
                }
                listenerTeamImgs[i] = new TeamCreateModelListener(null);
                labArrTeamImgs[i].addMouseListener(listenerTeamImgs[i]);
                this.add(labArrTeamImgs[i]);
            }
        }
        return labArrTeamImgs;
    }

    public void setLabArrTeamImgs(JLabel[] labArrTeamImgs) {
        this.labArrTeamImgs = labArrTeamImgs;
    }

    public TeamCreateBtn getBtnJoin() {
        if (btnJoin == null) {
            btnJoin = new TeamCreateBtn("skin/8100226/button/2.png", 1, UIUtils.COLOR_BTNTEXT, UIUtils.TEXT_FONT, "加入", 2, this);
            btnJoin.setBounds(378, 10, 34, 17);
            this.add(btnJoin);
        }
        return btnJoin;
    }

    public void setBtnJoin(TeamCreateBtn btnJoin) {
        this.btnJoin = btnJoin;
    }

    public TeamCreateBtn getBtnChat() {
        if (btnChat == null) {
            btnChat = new TeamCreateBtn("skin/8100226/button/2.png", 1, UIUtils.COLOR_BTNTEXT, UIUtils.TEXT_FONT, "交谈", 2,
                    this);
            btnChat.setBounds(414, 10, 34, 17);
            this.add(btnChat);
        }
        return btnChat;
    }

    public void setBtnChat(TeamCreateBtn btnChat) {
        this.btnChat = btnChat;
    }

    public JLabel getLabMsg() {
        if (labMsg == null) {
            labMsg = new JLabel("是兄弟就来砍我快来玩是兄弟就来砍我快来玩是兄弟就来砍我快");
            labMsg.setBounds(25, 40, 400, 16);
            labMsg.setForeground(Color.white);
            labMsg.setFont(UIUtils.TEXT_FONT1);
            this.add(labMsg);
        }
        return labMsg;
    }

    public void setLabMsg(JLabel labMsg) {
        this.labMsg = labMsg;
    }

	public TeamBean getTeamBean() {
		return teamBean;
	}
}
